<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="models.Brand, models.Category" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
%>





<html>
    <head>

        <title>byAMFI - New Product</title>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="<%=request.getContextPath()%>/style/style.css" type="text/css"/>    

    </head>

    <body id="bodyManagement">

        <div id="managementMenu">
            <a class="managementLink" href="../category/overview">CATEGORIES</a>  
            |  <a class="managementLink" href="../products/overview" style="font-size: 17px;"><b>PRODUCTS</b></a>
            |  <a class="managementLink" href="../brand/overview">BRANDS</a>
        </div>

        <div class="errors">
            <!--<p>test</p>-->

            <c:choose>
                <c:when test="${not empty errors}">
                    <!-- Als er geen id is meegegeven, ga je een gebruiker toevoegen -->
                    <c:forEach var="error" items="${errors}">
                        <b>${error}</b><br>
                    </c:forEach>
                </c:when>

                <c:otherwise>
                    <!--<p>no errors</p>-->
                </c:otherwise>
            </c:choose>
        </div>
        
        <div id ="newProduct">
            <c:choose>
                <c:when test="${empty product.product_id}">
                    <!-- Als er geen id is meegegeven, ga je een gebruiker toevoegen -->
                    <form id="nieuwNieuws" action="new" method="post" enctype="multipart/form-data">
                    </c:when>

                    <c:otherwise>
                        <!-- Anders ga je een gebruiker wijzigen -->
                        <form id="wijzigenNieuws" action="edit" method="post" enctype="multipart/form-data">
                        </c:otherwise>
                    </c:choose>

                    <p>
                        <c:if test="${not empty product.product_id}">
                            <!-- Het id wordt meegestuurd, om te bepalen welke gebruiker je gaat wijzigen -->
                            <input type="hidden" name="product_id" id="product_id" value="${product.product_id}" />
                            <input type="hidden" name="product_image_old" id="product_image_old" value="${product.product_image}" />

                        </c:if>
                    </p>

                    <table border="0">
                        <tr>
                            <td><label for="product_name">Product Name: </label></td>
                            <td><input class="inputBackground" type="text" id="product_name" name="product_name" value="${product.product_name}" /></td>
                        </tr>
                        <tr>
                            <td><label for="product_name">Product Description: </label></td>
                            <td><input class="inputBackground" type="text" id="product_description" name="product_description" value="${product.product_description}" /></td>
                        </tr>
                        <tr>
                            <td><label for="product_material">Product Material: </label></td>
                            <td><input class="inputBackground" type="text" id="product_material" name="product_material" value="${product.product_material}" /></td>
                        </tr>
                        <tr>
                            <td><label for="product_care">Product Care: </label></td>
                            <td><input class="inputBackground" type="text" id="product_care" name="product_care" value="${product.product_care}" /></td>
                        </tr>
                        <tr>
                            <td><label for="product_price">Product Author: </label></td>
                            <td><input class="inputBackground" type="text" id="product_author" name="product_author" value="${product.product_author}" /></td>
                        </tr>
                        <tr>
                            <td><label for="product_price">Product Price: </label></td>
                            <td><input class="inputBackground" type="text" id="product_price" name="product_price" value="${product.product_price}" /></td>
                        </tr>


                        <c:choose>
                            <c:when test="${not empty product.product_id}">
                                <!-- Als er geen id is meegegeven, ga je een gebruiker toevoegen -->
                                <tr>
                                    <td><label>Current Image: </label></td>
                                    <td><img style="height:50px;" src="<%=request.getContextPath()%>/products/uploads/${product.product_image}"/></td>
                                </tr>
                            </c:when>
                        </c:choose>
                        <tr>
                            <td><label for="product_image">Product Image: </label></td>
                            <td><input id="fileName" type="file" name="product_image" size="30"/><br/>      </td>
                        </tr>

                        <tr>
                            <td><label for="product_category">Product Category: </label></td>
                            <td><c:choose>
                                <c:when test="${empty product.product_id}">
                                <select name="product_category">
                                        <option>----</option>
                                        <c:forEach var="tempCategory" items="${category_list}">
                                            <option value="${tempCategory.category_id}">${tempCategory.category_name}</option>
                                        </c:forEach>
                                    </select>
                                </c:when>

                                <c:otherwise>
                                    <!-- Anders ga je een gebruiker wijzigen -->
                                   <select name="product_category">
                                        <option>----</option>
                                        <c:forEach var="tempCategory" items="${category_list}">
                                            <c:set var="category" value="${product.category}"/>
                                            <% Category category = (Category)pageContext.getAttribute("category");
                                            int resp = category.getCategory_id();
    //                                        out.write(merk.getBrand_name());
                                            pageContext.setAttribute("resp", resp);
                                            %>
                                            <option  value="${tempCategory.category_id}" <c:if test="${resp == tempCategory.category_id}"> selected='selected'</c:if>>${tempCategory.category_name}</option>
                                        </c:forEach>
                                    </select>
                                    </c:otherwise>
                                </c:choose>
                                </td>


                        <br/><br/>
                        <p></p>

                        </tr>
                        <tr>
                            <td><label for="product_brand">Product Brand: </label></td>
                            <td><c:choose>
                                <c:when test="${empty product.product_id}">
                                <select name="product_brand">
                                        <option>----</option>
                                        <c:forEach var="tempBrand" items="${brand_list}">
                                            <option  value="${tempBrand.brand_id}">${tempBrand.brand_name}</option>
                                        </c:forEach>
                                    </select>
                                </c:when>

                                <c:otherwise>
                                    <!-- Anders ga je een gebruiker wijzigen -->
                                   <select name="product_brand">
                                        <option>----</option>
                                        <c:forEach var="tempBrand" items="${brand_list}">
                                            <c:set var="brand" value="${product.brand}"/>
                                            <% Brand merk = (Brand)pageContext.getAttribute("brand");
                                            int resp = merk.getBrand_id();
    //                                        out.write(merk.getBrand_name());
                                            pageContext.setAttribute("resp", resp);
                                            %>
                                            <option  value="${tempBrand.brand_id}" <c:if test="${resp == tempBrand.brand_id}"> selected='selected'</c:if>>${tempBrand.brand_name}</option>
                                        </c:forEach>
                                    </select>
                                    </c:otherwise>
                                </c:choose>
                                </td>

                                </tr>

                                <tr><td>

                                        <br>
                                        <button type="submit" style="border: 0; background: transparent">
                                            <img src="../../style/images/button_addProduct.png" width="110" height="30" alt="submit" />
                                        </button>    

                                    </td></tr> 

                                </table>

                            </form>
                            </div>
                            </body>  
                            </html>